<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('大区会长预订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                    <input type="hidden" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                    <input type="hidden" id="orderState" name="params[orderState]"/>
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>大区会长：</label>
                                <input type="text" name="agentName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="orderState" th:with="type=${@dict.getType('agent_order_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>收货人：</label>
                                <input type="text" name="orderName"/>
                            </li>
                            <li>
                                <label>收货电话：</label>
                                <input type="text" name="orderPhone"/>
                            </li>
                            <li>
                                <label>详细地址：</label>
                                <input type="text" name="orderAddress"/>
                            </li>
                            <li>
                                <label>厂家名称：</label>
                                <input type="text" name="factoryName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

           <!-- <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zsyh:agentorder:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:agentorder:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:agentorder:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:agentorder:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:agentOrder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:agentOrder:remove')}]];
        var orderStateDatas = [[${@dict.getType('agent_order_state')}]];
        var isEnsurePlatformDatas = [[${@dict.getType('zsyh_yesno')}]];
        var prefix = ctx + "zsyh/agentOrder";
        var sumBalance = 0;
        var sumBalance1 = 0;
        //获取当前时间
        //判断是否在前面加0
        function getNow(s) {
            return s < 10 ? '0' + s: s;
        }
        var myDate = new Date();
        var year=myDate.getFullYear();        //获取当前年
        var month=myDate.getMonth()+1;   //获取当前月
        var date=myDate.getDate();            //获取当前日
        $("#startTime").val(year+'-'+getNow(month)+"-"+getNow(date)+" 00:00:00");
        $("#endTime").val(year+'-'+getNow(month)+"-"+getNow(date)+" 23:59:59");
        $("#orderState").val(0);
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                clickToSelect: true,
                rememberSelected: true,
                detailView: true,
                showFooter: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                modalName: "大区会长预订单",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'agentName',
                    align: 'center',
                    title: '大区会长'
                },
                {
                    field: 'orderName',
                    align: 'center',
                    title: '收货人'
                },
                {
                    field: 'orderPhone',
                    align: 'center',
                    title: '收货电话'
                },
                {
                    field: 'orderAddress',
                    align: 'center',
                    title: '详细地址'
                },
                {
                    field: 'factoryName',
                    align: 'center',
                    title: '厂家名称'
                },
                    {
                        field: 'orderBeginMoney',
                        align: 'center',
                        title: '预订合计金额',
                        footerFormatter:function (value) {
                            for (var i in value) {
                                if(value[i].orderBeginMoney != null && value[i].orderBeginMoney != '' && value[i].orderBeginMoney != undefined){
                                    sumBalance += parseFloat(value[i].orderBeginMoney);
                                }
                            }
                            return "总金额：" + sumBalance.toFixed(2);
                        }
                    },
                    /*{
                        field: 'orderEndMoney',
                        align: 'center',
                        title: '发货合计金额',
                        footerFormatter:function (value) {
                            for (var i in value) {
                                if(value[i].orderEndMoney != null && value[i].orderEndMoney != '' && value[i].orderEndMoney != undefined){
                                    sumBalance1 += parseFloat(value[i].orderEndMoney);
                                }
                            }
                            return "总金额：" + sumBalance1.toFixed(2);
                        }
                    },*/
                    {
                        field: 'orderState',
                        align: 'center',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(orderStateDatas, value);
                        }
                    },
                    {
                        field: 'createTime',
                        align: 'center',
                        title: '下单时间'
                    },
                /*{
                    field: 'isEnsurePlatform',
                    title: '平台是否已确认 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isEnsurePlatformDatas, value);
                    }
                },*/
                {
                    title: '操作',
                    align: 'center',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a style="background-color: #ec7e70;border-color: #ec7e70" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewOrder(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看详情</a> ');
                        /*actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/listChild",
                modalName: "产品规格",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: {
                    mid: row.id
                },
                columns: [
                    {
                        field : 'Number',
                        title : '序号',
                        align: 'center',
                        width: 30,
                        formatter : function(value, row, index) {
                            var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                            var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                            return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                        }
                    },
                    {
                        field: 'id',
                        title: '主键',
                        align: 'center',
                        visible: false
                    },
                    {
                        field: 'attributeLogo',
                        align: 'center',
                        title: '规格图',
                        formatter: function (value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                    {
                        field: 'partsName',
                        align: 'center',
                        title: '产品名称'
                    },
                    {
                        field: 'attributeName',
                        align: 'center',
                        title: '规格名称'
                    },
                    {
                        field: 'orderCount',
                        align: 'center',
                        title: '预订数量'
                    },
                    {
                        field: 'orderPrice',
                        align: 'center',
                        title: '预定单价'
                    },
                    {
                        field: 'orderSellCount',
                        align: 'center',
                        title: '发货数量'
                    },
                    {
                        field: 'orderSellPrice',
                        align: 'center',
                        title: '发货单价'
                    },{
                        field: 'orderBeginMoney',
                        align: 'center',
                        title: '预订合计金额',
                        formatter:function (value, row, index) {
                            return (row.orderCount * row.orderPrice).toFixed(2);
                        }
                    },
                    {
                        field: 'orderEndMoney',
                        align: 'center',
                        title: '发货合计金额',
                        formatter:function (value, row, index) {
                            return (row.orderSellCount * row.orderSellPrice).toFixed(2);
                        }
                    },]
            });
        };

        function viewOrder(id) {
            var url = ctx+"zsyh/agentOrder/viewOrder/"+id;
            layer.open({
                type: 2,
                area: ['1200px', '800px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看详情",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }

    </script>
</body>
</html>